import Observer from './observer.js'
import Compile from './compile.js'

function Vue(option) {
  this.$option = option
  this.$data = option.data
  this.$el = option.el
  this.$methods = option.methods
  this.$option.beforeCreate()
  new Observer(this.$data,this)
  this.$option.created()
  new Compile(this.$el,this)
  this.bindDataToThis()
}

Vue.prototype.bindDataToThis = function () {
  Object.keys(this.$data).forEach(key => {
    Object.defineProperty(this, key, {
      get () {
        return this.$data[key]
      },
      set (newVal) {
        this.$data[key] = newVal
      }
    })
  });
}

export default Vue